<?php
namespace jy_mayizlb;
defined('BY_JYA') or exit('error');
/*
*/
class member extends \plugin{
	public function check_shiming($mid=0,$backurl='',$rq=array()){
		$mid=$mid?:$_SESSION['uid'];
		$member=pdo_get('core_members',array('id'=>$mid));
		if(!$member['isrealname'] || !$member['realname'] || !$member['cardnum']){
			if($_SESSION['container']=='baiduapp' || $_SESSION['container']=='aliapp' || $_SESSION['container']=='ttapp' || $_SESSION['container']=='wxapp'){
				$_SESSION['backurl']=wxapp_links($backurl,$rq);
				return 1;
			}else{
				if(is_array($rq)){
					$query=http_build_query($rq);
				}
				$_SESSION['backurl']=$backurl.$query;
				exi('','','jy_mayizlb/index/');
			}
		}
		return false;
	}
	public function addlog($postdata=array()){
		$log=$this->pdo_get('log',array('mid'=>$_SESSION['uid'],'passed'=>0));
		$data=array(
			'ordersn'=>$postdata['ordersn'],
			'realname'=>$postdata['realname']?:$postdata['user_name'],
			'cardnum'=>$postdata['cardnum']?:$postdata['cert_no'],
			'mobile'=>$postdata['mobile'],
			'certifyid'=>$postdata['certifyId'],
			'certifyurl'=>$postdata['certifyUrl'],
			'passed'=>$postdata['passed']?:0,
			'backurl'=>$_SESSION['backurl'],
		);
		if($log['id']){
			$this->pdo_update('log',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$log['id']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			$data['createtime']=TIMESTAMP;
			$this->pdo_insert('log',$data);
			$log['id']=pdo_insertid();
		}
		return $log['id'];
	}
	public function check_passed($log=array()){
		$passed=0;
		$res=$this->model('model')->person_passed(array('certifyId'=>$log['certifyid']?:$log['certifyId'],'outerOrderNo'=>$log['ordersn']));
		if($res['passed']=='T'){
			$update=array(
				'isrealname'=>1,
			);
			pdo_update('core_members',$update,array('id'=>$log['mid']?:$_SESSION['uid']));
			$this->pdo_update('log',array('passed'=>1),array('id'=>$log['id']));
			$passed=1;
		}
		return $passed;
	}
	public function uppassed($log=array()){
			$update=array(
				'realname'=>$log['realname']?:$log['user_name'],
				'cardnum'=>$log['cardnum']?:$log['cert_no'],
				'isrealname'=>1,
			);
			pdo_update('core_members',$update,array('id'=>$log['mid']?:$_SESSION['uid']));
			$this->pdo_update('log',array('passed'=>1),array('id'=>$log['id']));
			return true;
	}
	public function isshibie($logid=0){
			$this->pdo_update('log',array('passed'=>3),array('id'=>$logid));
			return true;
	}
}